<?
require_once("includes_php/helpers/functions.php");
global $db;
if (empty($_GET['id'])) {
    header("Location: error.php?errorMsg=no_type");
}


$TYPE_OF_PAGE = 'full';
$TYPE_OF_MENU = 'menu_browse_filters';
include('layout_top.php');


$product = gsProducts::findById($db, mysql_escape_string($_GET['id']));
$price = $product->getPrice();
$brand = lookup_brandById($product->getLkBrand());
$type  = lookup_typeById($product->getLkType());
$desc  = $product->getShortDesc();
$modelNo = $product->getModelNo();

?>
<h1>Request a quote</h1>

<ul id="breadcrumb"> 
	<li><a href="index.php" title="Home"><img src="images/home.gif" alt="Home" class="home" /></a></li> 
	<li><a href="browse_by_type.php?type=<?=$product->getLkType()?>" title="<?=$type?>"><?=$type?></a></li> 
	<li><a href="browse_by_brand.php?brand=<?=$product->getLkBrand()?>" title="<?=$brand?>"><?=$brand?></a></li> 
	<li><?=$modelNo?></li> 
</ul> 
<br />

<table style="border-collapse: collapse; border: 0px; width: 100%;">
    <tr>
	<td style="border: 0; margin-top: 5px; vertical-align: top; width: 350px">
	   <table>
		<tr>
		    <td style="font-weight: bold;">Brand:</td>
		    <td><?=$brand?></td>
		</tr>
		<tr>
		    <td style="font-weight: bold;">Type:</td>
		    <td><?=$type?></td>
		</tr>
		<tr>
		    <td style="font-weight: bold;">Model number:</td>
		    <td><?=$modelNo?></td>
		</tr>
		<tr>
		    <td style="font-weight: bold;">Price:</td>
		    <td>$<?=$price?></td>
		</tr>
	    </table> 
	    <p>
	    <span style="font-weight: bold;">Description:</span> <?=$desc?>
	    </p> 
	</td>
	
	
	
	<td style="border: 0;">
	    
	    
	    <?
	    if(isset($_POST['Submit'])) {
		if(empty($_POST['fm-firstname']) || 
		   empty($_POST['fm-lastname']) ||
		   empty($_POST['fm-telephone']) ||
		   empty($_POST['fm-email'])
		) {
		   echo "<div class=\"error\">Please fill in all required fields.</div>"; 
		}
		else {
		    // Process the form.
		    isset($_POST['fm-firstname']) ? $firstname = mysql_escape_string($_POST['fm-firstname']) : $firstname = NULL;
		    isset($_POST['fm-lastname']) ? $lastname = mysql_escape_string($_POST['fm-lastname']) : $lastname = NULL;
		    isset($_POST['fm-company']) ? $company = mysql_escape_string($_POST['fm-company']) : $company = NULL;
		    isset($_POST['fm-addr1']) ? $addr1 = mysql_escape_string($_POST['fm-addr1']) : $addr1 = NULL;
		    isset($_POST['fm-addr2']) ? $addr2 = mysql_escape_string($_POST['fm-addr2']) : $addr2 = NULL;
		    isset($_POST['fm-city']) ? $city = mysql_escape_string($_POST['fm-city']) : $city = NULL;
		    isset($_POST['fm-state']) ? $state = mysql_escape_string($_POST['fm-state']) : $state = NULL;
		    isset($_POST['fm-zipcode']) ? $zipcode = mysql_escape_string($_POST['fm-zipcode']) : $zipcode= NULL;
		    isset($_POST['fm-country']) ? $country = mysql_escape_string($_POST['fm-country']) : $country = NULL;
		    isset($_POST['fm-telephone']) ? $telephone = mysql_escape_string($_POST['fm-telephone']) : $telephone = NULL;
		    isset($_POST['fm-email']) ? $email = mysql_escape_string($_POST['fm-email']) : $email = NULL;
		    isset($_POST['fm-comments']) ? $comments = mysql_escape_string($_POST['fm-comments']) : $comments = NULL;
		    
		    $message = "On " .  date("F j, Y, g:i a") . ", a quote has been submitted about item #".$_GET['id'] ." ( " . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?id=" . $_GET['id'] . " )\n";
		    $message .= "Name: " . $firstname . " " . $lastname . "\n";
		    $message .= "Company: " . $company . "\n";
		    $message .= "Address: " . $addr1 . "\n" . $addr2 . "\n";
		    $message .= "City: " . $city . "\n";
		    $message .= "State: " . $state . "\n";
		    $message .= "Zip code: " . $zipcode . "\n";
		    $message .= "Country: " . $country . "\n";
		    $message .= "Phone #: " . $telephone . "\n";
		    $message .= "Email: " . $email . "\n";
		    $message .= "Comments: " . $comments . "\n";
		    
		    $to = "sales@gstestequipment.com";
		    $subject = "[Quote Request] from " . $firstname . " " . $lastname;
		    
		    $headers = 'From: noreply@gstestequipment.com';
		    
		    
		    if(mail($to, $subject, $message, $headers)) {
			echo "<div class=\"notification\">Your request for a quote has been sent successfully!</div>";
		    }
		    else {
			echo "<div class=\"error\">There was an error requesting this quote.</div>";
		    }
		    
		}
	    }
	    ?>
	    

	    <div class="quote">	    
  <form id="fm-form" method="post" action="<?echo substr($_SERVER['PHP_SELF'], 1) . "?id=" . $_GET['id'];?>"> 
    <fieldset> 
    <legend>Personal information</legend> 
    <div class="fm-req"> 
      <label for="fm-firstname">First name:</label> 
      <input name="fm-firstname" id="fm-firstname" type="text" /> 
    </div> 
    <div class="fm-req"> 
      <label for="fm-lastname">Last name:</label> 
      <input name="fm-lastname" id="fm-lastname" type="text" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-company">Company:</label> 
      <input name="fm-company" id="fm-company" type="text" /> 
    </div> 
    </fieldset> 
    <fieldset> 
    <legend>Address </legend> 
    <div class="fm-opt"> 
      <label for="fm-addr1">Address 1:</label>
      <input id="fm-addr1" name="fm-addr1" type="text" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-addr2">Address 2:</label> 
      <input id="fm-addr2" name="fm-addr2" type="text" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-city">City or Town:</label> 
      <input id="fm-city" name="fm-city" type="text" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-state">State:</label> 
      <select id="fm-state" name="fm-state"> 
        <option value="" selected="selected">Choose a State</option> 
        <option value="UNK">Outside US / Canada</option> 
        <option value="AL">Alabama</option> 
        <option value="AK">Alaska</option> 
        <option value="AB">Alberta</option> 
        <option value="AS">American Samoa</option> 
        <option value="AZ">Arizona</option> 
        <option value="AR">Arkansas</option> 
        <option value="AA">Armed Forces Americas</option> 
        <option value="AE">Armed Forces Europe</option> 
        <option value="AP">Armed Forces Pacific</option> 
        <option value="BC">British Columbia</option> 
        <option value="CA">California</option> 
        <option value="CO">Colorado</option> 
        <option value="CT">Connecticut</option> 
        <option value="DE">Delaware</option> 
        <option value="DC">District Of Columbia</option> 
        <option value="FL">Florida</option> 
        <option value="GA">Georgia</option> 
        <option value="GU">Guam</option> 
        <option value="HI">Hawaii</option> 
        <option value="ID">Idaho</option> 
        <option value="IL">Illinois</option> 
        <option value="IN">Indiana</option> 
        <option value="IA">Iowa</option> 
        <option value="KS">Kansas</option> 
        <option value="KY">Kentucky</option> 
        <option value="LA">Louisiana</option> 
        <option value="ME">Maine</option> 
        <option value="MB">Manitoba</option> 
        <option value="MD">Maryland</option> 
        <option value="MA">Massachusetts</option> 
        <option value="MI">Michigan</option> 
        <option value="MN">Minnesota</option> 
        <option value="MS">Mississippi</option> 
        <option value="MO">Missouri</option> 
        <option value="MT">Montana</option> 
        <option value="NE">Nebraska</option> 
        <option value="NV">Nevada</option> 
        <option value="NB">New Brunswick</option> 
        <option value="NH">New Hampshire</option> 
        <option value="NJ">New Jersey</option> 
        <option value="NM">New Mexico</option> 
        <option value="NY">New York</option> 
        <option value="NF">Newfoundland</option> 
        <option value="NC">North Carolina</option> 
        <option value="ND">North Dakota</option> 
        <option value="MP">Northern Mariana Is</option> 
        <option value="NT">Northwest Territories</option> 
        <option value="NS">Nova Scotia</option> 
        <option value="OH">Ohio</option> 
        <option value="OK">Oklahoma</option> 
        <option value="ON">Ontario</option> 
        <option value="OR">Oregon</option> 
        <option value="PW">Palau</option> 
        <option value="PA">Pennsylvania</option> 
        <option value="PE">Prince Edward Island</option> 
        <option value="PQ">Province du Quebec</option> 
        <option value="PR">Puerto Rico</option> 
        <option value="RI">Rhode Island</option> 
        <option value="SK">Saskatchewan</option> 
        <option value="SC">South Carolina</option> 
        <option value="SD">South Dakota</option> 
        <option value="TN">Tennessee</option> 
        <option value="TX">Texas</option> 
        <option value="UT">Utah</option> 
        <option value="VT">Vermont</option> 
        <option value="VI">Virgin Islands</option> 
        <option value="VA">Virginia</option> 
        <option value="WA">Washington</option> 
        <option value="WV">West Virginia</option> 
        <option value="WI">Wisconsin</option> 
        <option value="WY">Wyoming</option> 
        <option value="YT">Yukon Territory</option> 
      </select> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-zipcode">Zip code:</label> 
      <input id="fm-zipcode" name="fm-zipcode" type="text" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-country">Country:</label> 
      <input id="fm-country" name="fm-country" type="text" /> 
    </div> 
    </fieldset> 
    <fieldset> 
    <legend>Contact information</legend> 
    <div class="fm-req"> 
      <label for="fm-telephone">Phone:</label> 
      <input id="fm-telephone" name="fm-telephone" type="text" title="Enter number and extension"/> 
    </div>
    <div class="fm-req"> 
      <label for="fm-email">Email:</label> 
      <input id="fm-email" name="fm-email" type="text" tabindex="" /> 
    </div> 
    <div class="fm-opt"> 
      <label for="fm-comments">Comments:</label> 
      <textarea name="fm-comments" cols="20" rows="5" id="fm-comments"></textarea> 
    </div> 
    </fieldset> 
    <div id="fm-submit" class="fm-req"> 
      <input name="Submit" value="Submit" type="submit" /> 
    </div> 
  </form> 
	    </div>	    
	    
	    
	    
	    
	</td>
    </tr>
</table>



<?

include('layout_bottom.php');
?>
